<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('需求列列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <style>
        table td{
            max-width: 285px;
        }
    </style>
</head>
<body class="gray-bg">
    <div class="ui-layout-west" style="width:300px;">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 选择项目
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>

    <div class="ui-layout-center">
         <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" name="treeType" id="treeType"/>
                        <input type="hidden" name="projectId" id="projectId"/>
                        <div class="select-list">
                            <ul>
                                <li>
                                    <p>需求分类：</p>
                                    <select name="reqType" th:with="type=${@dict.getType('sys_req_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <p>需求状态：</p>
                                    <select name="reqStatus" th:with="type=${@dict.getType('sys_req_status')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li class="select-time">
                                    <p>提出时间：</p>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginBeginTime]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endBeginTime]"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="requirementAdd()" shiro:hasPermission="system:requirement:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:requirement:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:requirement:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-primary" onclick="assign()">
                        <i class="fa fa-user-plus"></i> 分配任务
                    </a>
                    <a class="btn btn-warning" onclick="daily()">
                        <i class="fa fa-calendar"></i> 生成日报
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:requirement:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:requirement:remove')}]];
        var reqTypeDatas = [[${@dict.getType('sys_req_type')}]];
        var reqStatusDatas = [[${@dict.getType('sys_req_status')}]];
        var reqPriDatas = [[${@dict.getType('sys_req_pri')}]];
        var prefix = ctx + "system/requirement";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 240 });
            queryRequirementList();
            queryDeptTree();
        });

        //填写日志
        function compile(reqId){
            $.modal.open("填写日志","/system/record/add?reqId="+reqId);
        }
        //任务分配
        function assign(){
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条需求");
                return;
            }
            $.modal.open("任务分配", "/system/requirement/assign?reqIds="+rows.join());
        }

        //生成日报
        function daily(){
            var options = {
                title: "生成日报",
                url: "/system/record/daily",
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        //查看详细
        function detail(reqId) {
            $.modal.open("需求管理", "/system/requirement/detail?reqId="+reqId);
        }

        function queryRequirementList(){
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add?{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                compileUrl:prefix+"/compile",
                modalName: "需求列",
                columns: [{
                    checkbox: true
                },
                    {
                        field : 'reqId',
                        title : 'id',
                        visible: false
                    },
                    {
                        field : 'reqSerial',
                        title : '编号',
                        align: 'center',
                    },
                    {
                        field : 'reqContent',
                        title : '需求内容'
                    },
                    {
                        field : 'reqType',
                        title : '需求分类',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(reqTypeDatas, value);
                        }
                    },
                    {
                        field : 'updateTime',
                        title : '更新时间',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return changeDateFormat(value);
                        }
                    },
                    {
                        field : 'reqStatus',
                        title : '需求状态',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(reqStatusDatas, value);
                        }
                    },
                    {
                        field : 'devUser',
                        title : '开发人员',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var userName;
                            if(value!=null){
                            $.ajax({
                                type:'post',
                                url: '/system/user/getUsername',
                                data:"userId="+value,
                                async: false,
                                success: function(data){
                                    var user= JSON.parse(data);
                                    userName = user.userName;
                                }
                            });
                            }
                            return userName;
                        }
                    },
                    {
                        field : 'reqPri',
                        title : '优先级',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(reqPriDatas, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.reqId + '\')"><i class="fa fa-filter"></i>管理</a>&nbsp;');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="compile(\'' + row.reqId + '\')"><i class="fa fa-pencil"></i>填写日志</a> ');
                            /*actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="compile(\'' + row.reqId + '\')"><i class="fa fa-remove"></i>编辑</a>');*/
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        function queryDeptTree()
        {
            var url = ctx + "geocode/requiretreeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#treeType").val(treeNode.type);
                $("#projectId").val(treeNode.id);
                $.table.search();
            }
        }

        //转换日期格式(时间戳转换为datetime格式)
        function changeDateFormat(cellval) {
            if (cellval != null) {
                var date = new Date(cellval);
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

                var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

                return month + "-" + currentDate + " " + hours + ":" + minutes;
            }
        }

        function requirementAdd(){
            if($("#treeType").val() == '1' && $("#projectId").val() != '100000'){
                var params = "projectId=" + $("#projectId").val();
                $.operate.add(params);
            }else{
                $.modal.alertWarning("请选择一个项目！");
            }
        }
    </script>
</body>
</html>